Page({
    data: {
      tabs: [],
      activeTab: 0,
      courses:[],
      showing_courses:[],
      pageSort:1
    },
  
    onLoad() {
        var that = this
        wx.request({
          url: 'https://data.docta.asia:8000/CourseData/',
          method:'post',
          data:(
              {
                  pageSort:this.data.pageSort
              }
          ),
          header: {         
            "Content-Type": "application/x-www-form-urlencoded;charset = utf-8 "
        },
        //成功返回值时    
 

        success:function(res){    
            console.log(res)  
            // 获取tabs的值
            const titles = res.data.titles
            const tabs = titles.map(item => ({title: item}))
            that.setData({tabs})  

            //获取课程详细内容的值
            const course_copy=res.data.courses
            const courses=course_copy.map(item => ({course_name : item}))
            that.setData({courses}) 
            console.log(that.data.courses)
        }    
        }) 
    },
  
    onTabCLick(e) {
      const index = e.detail.index
      this.setData({activeTab: index})
      this.setData(this.data.showing_courses=this.data.courses[index])
    },
  
    onChange(e) {
      const index = e.detail.index
      this.setData({activeTab: index})
      this.setData(this.data.showing_courses=this.data.courses[index])
    },
  
  })

// Page({
//     data: {
//       tabs: [],
//       activeTab: 0,
//       tabs=['首页', '外卖', '商超生鲜', '购物', '美食饮品', '生活服务', '休闲娱乐', '出行'],
//     },
    
//     onLoad() {
//       const titles = ['首页', '外卖', '商超生鲜', '购物', '美食饮品', '生活服务', '休闲娱乐', '出行']
//       const tabs = titles.map(item => ({title: item}))
//       this.setData({tabs})
//     },
  
//     onTabCLick(e) {
//       const index = e.detail.index
//       this.setData({activeTab: index})
//     },
  
//     onChange(e) {
//       const index = e.detail.index
//       this.setData({activeTab: index})
//     }
//   })
  